<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Validate user when user login</title>
</head>
<body>
<% 
Class.forName("com.mysql.jdbc.Driver").newInstance();   
String url ="jdbc:mysql://localhost/bbs?user=root&password=123456&useUnicode=true&characterEncoding=8859_1";
ResultSet rs =  null;
Connection conn= DriverManager.getConnection(url);
String userName = request.getParameter("username");
String passwordFromDatabase;
String password = request.getParameter("password");
PreparedStatement stmt = conn.prepareStatement("Select password from User where name = ? ;");
stmt.setString(1,userName);
rs = stmt.executeQuery();
if( rs.next()){
	passwordFromDatabase = rs.getString("password").trim();
//	out.println("yours " + password + "right one is" + passwordFromDatabase );
	if(password.equals(passwordFromDatabase)){
		out.println("yourlogin successful!" );
		session.setAttribute("login_user",userName);
		response.sendRedirect("index.jsp");
		
	}else {
		out.println("your password is wrong!" );
	}
	
	

}else{
	out.println("This name is not registered!");
}
%>
<br>
this is validate user page!
</body>
</html>